package com.totoro.springboot.jpa_batch.dao.impl;

import com.totoro.springboot.jpa_batch.dao.AbstractDao;
import com.totoro.springboot.jpa_batch.dao.IUserDao;
import com.totoro.springboot.jpa_batch.model.User;
import com.totoro.springboot.jpa_batch.repository.UserRepository;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Niki on 2018/4/18 10:57
 */
@Repository
public class UserDaoImpl extends AbstractDao<User> implements IUserDao {
    @Resource
    UserRepository repository;

    @Override
    public void save(User user) {
        repository.save(user);
    }

    @Override
    @Transactional
    //在使用EntityManager的方法上必须要加事务
    public void batchSaveUser(List<User> users) {
        batchInsert(users);
    }

    @Override
    public User update(User user) {
        return repository.save(user);
    }

    @Override
    public int batchUpdateUser(List<User> users) {
        batchUpdate(users);
        return 0;
    }




}
